<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../../php/config/database.php";
require_once "userDb.php";
$UserDb=new UserDb();
session_start();
$use = $_SESSION['user'];
$id=$_POST['id'];
$user=$_POST['user'];
$class=$_POST['class'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$url=$_POST['url'];
$pass=$_POST['pass'];
$addtime=time();
if(!$use=="") {

    $dataA = $UserDb->queryAdUpadte($user);
    if ($dataA == null) {
        if($pass===""){
            $data = $UserDb->updateUserA($id, $user, $class, $url, $tel, $email, $addtime);
            try {
                $result = $data;
                if ($result) {
                    $dat = array(
                        'message' => "修改成功",

                    );
                    echo json_encode($dat);
                } else {
                    $dat = array(

                        'message' => "修改失败",

                    );
                    echo json_encode($dat);

                }
            } catch (Exception $e) {

                // 回滚事务
                // $pdo->rollback();
                echo $e->getMessage();
            }
        }else {

            $pass = md5($pass);
            $data = $UserDb->updateUserPass($id, $user, $pass, $class, $url, $tel, $email, $addtime);


            try {
                $result = $data;
                if ($result) {
                    $dat = array(
                        'message' => "修改成功",

                    );
                    echo json_encode($dat);
                } else {
                    $dat = array(

                        'message' => "修改失败",

                    );
                    echo json_encode($dat);

                }
            } catch (Exception $e) {

                // 回滚事务
                // $pdo->rollback();
                echo $e->getMessage();
            }
        }
    } else {


        $dat = array(

            'message' => "该账号以及存在，请换一个账号",


        );
        echo json_encode($dat);
    }

}else{
    echo "<script>window.location.href='../../view/login.html';</script>";
}